package com.xwh.week4;

import java.util.HashSet;

public class Practice7 {
    public static void main(String[] args) {
        HashSet<Integer> integers = new HashSet<>();
        int ans=0;
        for(int i=10;i<1000000;i++){
           if(method(i)){
               integers.add(i);
               ans+=i;
           }
       }
        System.out.println(ans);
    }
    public static boolean method(int n){
        Integer l=n;
        String s = l.toString();
        int length = s.length();
        boolean[][] bool=new boolean[length][length];
        for(int j=0;j<length;j++){//第一行判断
            String s1=s.substring(0,j+1);
          bool[0][j]=method1(s.substring(0,j+1));
          if(bool[0][j]==false){
              return false;
          }
        }
        for(int i=0;i<length;i++){
            String s2=s.substring(i,length);
            bool[i][length-1]=method1(s.substring(i,length));
            if(bool[i][length-1]==false){
                return false;
            }
        }
        return true;
    }
    public static boolean method1(String s){
        Integer i = new Integer(s);
        int num=i;
        return method2(num);
    }
    public static boolean method2(int n){
        if(n<2){
            return false;
        }
        boolean flag=true;
        int sqrt = (int)Math.sqrt(n);
        for(int i=2;flag&&i<=sqrt;i++){
            flag=n%i!=0;
        }
        return flag;
    }
}
